package com.dcbeida.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dcbeida.R;
import com.dcbeida.bean.Kcpdbg;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 库存盘点报告
 */
public class KcpdbgAdapter extends BaseAdapter {

    private ArrayList<Kcpdbg.ListBean> mArrayList = new ArrayList<>();
    private Context mContext;

    public KcpdbgAdapter(Context context) {
        super();
        this.mContext = context;
    }


    @Override
    public int getCount() {
        if (mArrayList == null) {
            return 0;
        } else {
            return this.mArrayList.size();
        }
    }

    @Override
    public Object getItem(int position) {
        if (mArrayList == null) {
            return null;
        } else {
            return this.mArrayList.get(position);
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.kcpdbg_item, null, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Kcpdbg.ListBean bean = mArrayList.get(position);
        holder.tvPdsj.setText(bean.getCreatetime());
        holder.tvPds.setText(bean.getInventory());
        holder.tvKcs.setText(bean.getStock());
        if ("".equalsIgnoreCase(bean.getOverage()) || bean.getOverage().equalsIgnoreCase("0")) {
            holder.tvPys.setText("0");
        } else {
            holder.tvPys.setText("+" + bean.getOverage());

        }

        if ("".equalsIgnoreCase(bean.getShortage()) || bean.getShortage().equalsIgnoreCase("0")) {
            holder.tvPks.setText("0");
        } else {
            holder.tvPks.setText("+" + bean.getShortage());
        }

        return convertView;
    }


    public ArrayList<Kcpdbg.ListBean> getmArrayList() {
        return mArrayList;
    }

    public void setmArrayList(ArrayList<Kcpdbg.ListBean> mArrayList) {
        if (mArrayList.size() >= 0) {
            this.mArrayList.addAll(mArrayList);
        }
        notifyDataSetChanged();
    }

    public void clearList() {
        this.mArrayList.clear();
    }


    static class ViewHolder {

        @Bind(R.id.tv_pdsj)
        TextView tvPdsj;
        @Bind(R.id.tv_pds)
        TextView tvPds;
        @Bind(R.id.tv_kcs)
        TextView tvKcs;
        @Bind(R.id.tv_pys)
        TextView tvPys;
        @Bind(R.id.tv_pks)
        TextView tvPks;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
